Ext.ns("CRM.SPComp");

(function(){
	
	CRM.SPComp.createSetupColumnModel = function(){
		
		var setupColModel = new Ext.grid.ColumnModel([
		      {
		    	  header    : 'Source',
		    	  width     : 100,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'source'
		      },
		      {
		    	  header    : 'Grade',
		    	  width     : 90,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'grade'
		      },
		      {
		    	  header    : 'Action',
		    	  width     : 100,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'action' 
		      },
		      {
		    	  header    : 'Category',
		    	  width     : 100,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'category'
		      },
		      {
		    	  header    : 'Stage',
		    	  width     : 100,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'stage'
		      },
		      {
		    	  header    : 'Probability',
		    	  width     : 120,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'probability'
		      },
		      {
		    	  header    : 'Industry Type',
		    	  width     : 140,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'industrytype'
		      },
		      {
		    	  header    : 'Status',
		    	  width     : 100,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'status'
		      },
		      {
		    	  header    : 'Activity Type',
		    	  width     : 140,
		    	  align     : 'center',
		    	  sortable  : false,
		    	  index     : 'activitytype'
		      }
		                                                  
		   ]);
		return setupColModel;
	};
	

	
	CRM.SPComp.uploadDocDataArray=['documentType','documentName', 'receiveDate', 'fileName', 'fileSize', 'tag', 'fileContent'];
	CRM.SPComp.createUploadDocColumnModel = function(){
		var docUploadColModel = new Ext.grid.ColumnModel([
				{
					header 		: 'Document Type',
					width		: 120,
					align		: 'left',
					dataIndex	: 'documentType', 
					enableColumnHide : false
				},
				{
					header 		: 'Document Name',
					width		: 140,
					align		: 'left',
					dataIndex	: 'documentName',
					enableColumnHide : false
				},
				{
					header 		: 'Receive Date',
					width		: 100,
					align		: 'left',
					dataIndex	: 'receiveDate',
					enableColumnHide : false
				},
				{
					header 		: 'File Name',
					sortable 	: true,
					width		: 200,
					align		: 'left',
					dataIndex	: 'fileName',
					enableColumnHide : false
				},
				{
					header 		: 'File Size (KB)',
					width		: 100,
					align		: 'right',
					dataIndex	: 'fileSize',
					enableColumnHide : false
				},
				{
	       	    	hidden      : true,
	       	    	header      : 'File Content',
	       	    	index       : 'fileContent',
	       	    	sortable    : true
	       	    },
				{
	    			xtype		: 'actioncolumn',
	    			header  	: 'Action',
	    			id          : 'leadActionColumn',
	    			align		: 'center',
	    		    width		: 60,
	    			items		:[{
	    						   icon	: '../images/view.jpg ',
	    						   handler : function(){
	    											//uploadDocumentViewWin(); //This window is written in FileUploader.js to view the upload document
	    				                            viewDocument(); //THIS FUNCTON IS WRITTEN IN LEAD.JS TO VIEW DOCUMENT
	    						   				}
	    			     	      }]
				}
		 ]);
		return docUploadColModel;
	};	
	
	//image path
	var INITIAL_IMG = '../images/initial.png';
	var INPROCESS_IMG = '..//images/orange.png';
    var COMPLETED_IMG = '..//images/green.png';
	 
	//renderer function
	function renderStageIcon(val) {
     if(val == 'INITIAL')
        return  '<img src="' + INITIAL_IMG  + '"> ' + val  ;
     if(val == 'INPROCESS')
         return  '<img src="' + INPROCESS_IMG   + '"> ' + val  ;
     if(val == 'COMPLETED')
         return  '<img src="' + COMPLETED_IMG  + '"> ' + val  ;
    }

	CRM.SPComp.leadDataArray=['id','firstName','middleInitial','lastName','companyName','phone1','phone2','stage','email','title','grade','assignedTo'];
	CRM.SPComp.createLeadColumnModel = function(gridid){
		
		var leadColModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'id',
       	        hidden		: true
       	    },		                                 		
       	    {
       	        header 		: 'First Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'firstName'
       	    },
       	    {
       	        header 		: 'M.I.',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'middleInitial',
       	        width		: 40,
       	        hidden		: true
       	    },
       	 	{
       	        header 		: 'Last Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'lastName'
       	    },               	    
       	 	{
       	        header 		: 'Company',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'companyName',
       	        width       : 150
       	    },
       	 	{
       	        header 		: 'Phone(W)',
       	        align		: 'left',
       	        index       : 'phone1',
       	        sortable	: false,
       	        hidden		: true
       	    },
       	 	{
       	        header 		: 'Phone(M)',
       	        align		: 'left',
       	        index       : 'phone2',
       	        sortable	: false
       	    },
    	    
       	    {
       	        header 		: 'Stage',
       	        align		: 'left',
       	        index       : 'stage',
       	        sortable	: true,
       	        width       : 80,
      	        renderer	: renderStageIcon
       	    },
       	    {
    	       	header 		: 'Email',
    	       	width		: 160,
      	        align		: 'left',
      	        index       : 'email',
      	        sortable	: true
    	    },
	       	
	 	    {
	 	    	header      : 'Title',
	 	    	width		: 150,
	 	    	align       : 'left',
	 	    	index       : 'title',
	 	    	sortable    : true
	 	    },
       	 	{
       	        header 		: 'Grade',
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'grade',
       	        width       : 70
       	    },
       	 	{
       	        header 		: 'Assign To',
       	        align		: 'center',
       	        sortable	: true,
       	        width       : 70
       	    },
    		{
    			xtype		: 'actioncolumn',
    			header  	: 'Action',
    			id          : 'leadActionColumn',
    			align		: 'center',
    		    width		: 80,
    			items		:[
    			     	     {
    						   icon	: '../images/view.jpg ',
    						   handler : function(cm, rowIndex, colIndex){
    							 			var record = Ext.getCmp(gridid).store.getAt(rowIndex);
    			     	    	 	    	showLeadDetails(record.get('id'));//record
    						   			 }
    			     	      },
    			     	      {
    			     	    	 icon	 : '../images/cross.gif',
	    					     id		 : 'deactivateIcon',
	    						 tooltip : 'Deactivate',
	    						 handler : function(cm, rowIndex, colIndex) {
	    							 	    var record = Ext.getCmp(gridid).store.getAt(rowIndex);
       	    	                           	deactivateLead(record.get('id'), false); //this method is in lead.js
            	    	                 }
    	     	  			}
    			     	  ]
    		}
       ]);
		return leadColModel;
	};
	

	CRM.SPComp.contactDataArray=['id','firstName', 'lastName','title','email','workPhone','homePhone','mobileNo','fax'];
	CRM.SPComp.createContactColumnModel = function(){
		
		var contactColModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'id',
       	        hidden		: true
       	    },		                                 		
       	    {
       	        header 		: 'First Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'firstName'
       	    },
       	 	{
       	        header 		: 'Last Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'lastName'
       	    },               	    
       	 	{
       	        header 		: 'Title',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'title',
       	        width       : 180
       	    },
       	    {
    	       	header 		: 'Email',
    	       	width		: 210,
      	        align		: 'left',
      	        index       : 'email',
      	        sortable	: true
    	    }       	    
       	    ,
       	 	{
       	        header 		: 'Phone(W)',
       	        align		: 'center',
       	        index       : 'workdPhone',
       	        align		: 'left',
       	        sortable	: false
       	    },
       	 	{
       	        header 		: 'Phone(M)',
       	        align		: 'center',
       	        index       : 'homePhone',
       	        align		: 'left',
       	        sortable	: false
       	    },
       	 	{
       	        header 		: 'Phone(H)',
       	        align		: 'center',
       	        index       : 'mobileNo',
       	        align		: 'left',
       	        sortable	: false
       	    },    	    
       	 	{
       	        header 		: 'FAX',
       	        align		: 'center',
       	        index       : 'fax',
       	        align		: 'left',
       	        sortable	: false
       	    },       	    
    		{
    			xtype		: 'actioncolumn',
    			header  	: 'Action',
    			align		: 'center',
    			width		: 50,
    			items		:[
	    			     	   {
	    						 icon	: '../images/view.jpg',
	    						 handler : function(cm, rowIndex, colIndex){
	    							 			var leadGrid = Ext.getCmp('spSearchLeadGridPanel');
	    							 			var customerGrid = Ext.getCmp('spSearchCustomerGridPanel');
		    							 		if(leadGrid != null){
		    							 			var contactRow = Ext.getCmp('contactsGrid').store.getAt(rowIndex);
		    							 			var leadId = Ext.getCmp('leadId').getValue();
		    							 			var contactId = contactRow.get('id');
		    							 			showContactScreen(true, leadId, contactId);
		    							 		}
		    							 		if(customerGrid != null){
		    							 			var contactRow = Ext.getCmp('contactsGrid').store.getAt(rowIndex);
		    							 			var customerId = Ext.getCmp('customerId').getValue();
		    							 			var contactId = contactRow.get('id');
		    							 			showContactScreen(true, customerId, contactId);
		    							 		}else{
		    							 			/*
		    							 			 * If ever additional search screen will be created like Lead, Customer or Opportunity,
		    							 			 * then a method will be created in that .jsp and will be called here.
		    							 			 * Please check Action column of ActivityDataArray column model for reference.
		    							 			 */
		    							 		}
	    			     	   					
	    							 		}	
	    	     	  			},
	    	     	  			'-',
	    	     	  			{
	     	     	  				icon    : '../images/cross.gif',
	     	     	  				id      :'deleteIcon',
	     	     	  				tooltip :'Delete',
	     	     	  				handler :function(){
	     	     	  				           showMessage();  
	     	     	  			 }
	    	     	  			}
	    			     	   ]
    		}
       ]);
		return contactColModel;
	};	
	
	CRM.SPComp.customerDataArray=['id','firstName','middleInitial','lastName','companyName','phone1','phone2','stage','email','title','grade','assignedTo'];
	CRM.SPComp.createCustomerColumnModel = function(){
		
		var leadColModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'id',
       	        hidden		: true
       	    },		                                 		
       	    {
       	        header 		: 'First Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'firstName'
       	    },
       	    {
       	        header 		: 'M.I.',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'middleInitial',
       	        width		: 40,
       	        hidden		: true
       	    },
       	 	{
       	        header 		: 'Last Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'lastName'
       	    },               	    
       	 	{
       	        header 		: 'Company',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'companyName',
       	        width       : 150
       	    },
       	 	{
       	        header 		: 'Phone(W)',
       	        align		: 'center',
       	        index       : 'phone1',
       	        sortable	: false
       	    },
       	 	{
       	        header 		: 'Phone(M)',
       	        align		: 'center',
       	        index       : 'phone2',
       	        sortable	: false,
       	        hidden		: true
       	    },
    	    
       	    {
       	        header 		: 'Stage',
       	        align		: 'center',
       	        index       : 'stage',
       	        sortable	: true,
       	        width       : 80
       	    },
       	    {
    	       	header 		: 'Email',
    	       	width		: 160,
      	        align		: 'left',
      	        index       : 'email',
      	        sortable	: true
    	    },
	       	
	 	    {
	 	    	header      : 'Title',
	 	    	align       : 'left',
	 	    	index       : 'title',
	 	    	sortable    : true
	 	    },
       	 	{
       	        header 		: 'Grade',
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'grade',
       	        width       : 70
       	    },
       	 	{
       	        header 		: 'Assign To',
       	        align		: 'center',
       	        sortable	: true,
       	        width       : 70
       	    },
    		{
    			xtype		: 'actioncolumn',
    			header  	: 'Action',
    			align		: 'center',
    			width		:  60,
    			layout		:'column',
    			padding		: '10px',
    			items		:[
    			     	     {
    						   icon	   : '../images/view.jpg',
    	     	  			   tooltip : 'Details',
    						   handler : function(cm, rowIndex, colIndex){
    							   			var record = Ext.getCmp('spSearchCustomerGridPanel').store.getAt(rowIndex);
    							   			var selectedCustomerId = record.get('id');
    							 			showCustomerDetails(selectedCustomerId); //this method is in customer.jsp file
    							 		}	
    	     	  			}
    	     	  		]
    		}
       ]);
		return leadColModel;
	};	
	
	
	CRM.SPComp.opportunityDataArray=['id','opportunityTitle','companyName','salesPerson','salesPersonId','oppClosingProbability','dealSize','stage','stageId','actualCloseDate','targetDate','createDate','opportunityDiscription','status','statusId','oppClosingProbabilityId'];
    CRM.SPComp.createOpportunityColumnModel = function(){	
    	
		var opportunityColumnModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'id',
       	        menuDisabled: true,
       	        hidden		: true
       	    },		                                 		
       	    {
       	        header 		: 'Opportunity Title',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'opportunityTitle',
       	        sortable    : true,
       	        width		: 230,
       	        menuDisabled: true
       	    },       	   
       	    {
       	    	header     : 'Company Name',
       	    	align      : 'left',
       	    	sortable   : true,
       	    	width      : 190,
       	    	index      : 'companyName',
       	    	sortable   : true,
       	        menuDisabled: true
       	    },
       	 	  
       	 	{
       	        header 		: 'Sales Person',
       	        sortable	: true,
       	        index		: 'salesPerson',
       	        align       : 'left',
       	        width		: 150,
       	        sortable    : true,
       	        menuDisabled: true
       	    },
       	    	{hidden : true,index : 'salesPersonId'},
       	    
       	    {
       	        header 		: 'Conf. Level',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'oppClosingProbability',
       	        width		: 120,
       	        menuDisabled: true
       	    },
       	    	{hidden	: true,index : 'oppClosingProbabilityId'},

       	 	{
       	        header 		: 'Stage',
       	        align		: 'left',
       	        sortable	: true,
       	        index       : 'stage',
       	        width		: 100,
       	        menuDisabled: true
       	    },{hidden	: true,index : 'stageId'},
       	    
            {
       	    	hidden      : true,
       	        header 		: 'Deal Size',
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'dealSize',
       	        width		: 100
       	    },
       	    {hidden     : true,index      : 'status'},
       	    {hidden     : true,index      : 'statusId'},
       	    
       	 	{
       	    	hidden      : true,
       	        header 		: 'Created Date',
       	        index       : 'createDate',
       	        align		: 'center',
       	        sortable	: true,
       	        width		: 100
       	    },
    	    {
       	    	hidden      : true,
    	       	header 		: 'Target Date',
    	       	width		: 210,
    	       	index       : 'targetDate',
      	        align		: 'center',
      	        sortable	: true,
      	        width		: 100
    	    },
       	    {
    	    	hidden      : true,
       	        header 		: 'Close Date',
       	        align		: 'center',
       	        index       : 'actualCloseDate',
       	        sortable	: true,
       	        width		: 100
       	    },
       	    {
       	    	hidden      : true,
       	    	header      : 'Opportunity Description',
       	    	index       : 'opportunityDiscription',
       	    	sortable    : true
       	    },
       	    {
    			xtype		: 'actioncolumn',
    			id          : 'opportunityActionColumn',
    			header  	: 'ACTION',
    			align		: 'center',
    			width		: 110,
       	        menuDisabled: true,
    			items		:[
    			     	   {
    						 icon	: '../images/view.jpg',
    						 handler : function(cm, rowIndex, colIndex){
    							 			var leadGrid = Ext.getCmp('spSearchLeadGridPanel');
    							 			var customerGrid = Ext.getCmp('spSearchCustomerGridPanel');
	    							 		if(leadGrid != null){
	    							 			var griddata = Ext.getCmp('opportunitiesGrid');
    							 				var rowdata = griddata.store.getAt(rowIndex);
    							 				var selectedLeadId = Ext.getCmp('leadId').getValue();
    							 				CRM.SPComp.showOpportunityWindow(selectedLeadId,'0',rowdata);
    							 			}
	    							 		if(customerGrid != null){
	    							 			var griddata = Ext.getCmp('opportunitiesGrid');
    							 				var rowdata = griddata.store.getAt(rowIndex);
    							 				var selectedCustomerId = Ext.getCmp('customerId').getValue();
    							 				CRM.SPComp.showOpportunityWindow(selectedCustomerId,'0',rowdata);
    							 			}
	    							 		if(Ext.getCmp('opportunitygridId') != null){
    							 				var record = Ext.getCmp('opportunitygridId').store.getAt(rowIndex);
    							 				showOpportunityDetails(record.get('id')); //this method is in opportunity.js file
    							 			}
    							 		}	
    	     	  			},
    	     	  			'-',
    	     	  			{
	    						 icon	: '../images/cross.gif',
	    						 id		: 'deleteIcon',
	    						 tooltip:'Delete',
	    						 handler: function() {
    	     	  							showOppMessage();  //this method inside Opportunity.js to generate details
            	    	                 }
	    				    }
    			     	  ]
    		},
    		 
       ]);
		return opportunityColumnModel;
	};
	
	CRM.SPComp.activityDataArray=['id','dueDate','activityType','salesPerson','createdBy','contactTo','opportunityTitle','stage','status','priority',
	                              'activityTypeId','salesPersonId','subject', 'dueDate', 'duration', 'reminder', 'reminderDate', 
	                              'opportunityTitleId','stageId','statusId','priorityId','activityNotes'];
	CRM.SPComp.createActivityColumnModel = function(){
		var activityColumnModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 40,
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'id',
       	        hidden		: true
       	    },		                                 		
       	    {
       	        header 		: 'Due Date',
       	        align		: 'center',
       	        sortable	: true,
       	        width		: 80,
       	        index		: 'dueDate'
       	    },
       	 	{
       	        header 		: 'Activity Type',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 80,
       	        index		: 'activityType'
       	    },      
       	    {
       	        header 		: 'Sales Person',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 120,
       	        index		: 'salesPerson'
       	    },    
       	    {
       	    	header		: 'Created By',
       	    	align		: 'left',
       	    	sofrtable	: true,
       	    	width		: 120,
       	    	index		: 'createdBy'
       	    },
       	 	{
       	        header 		: 'Contact To',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 120,
       	        index		: 'contactTo'
       	    },
       	 	{
       	        header 		: 'Opportunity Title',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 170,
       	        index		: 'opportunityTitle'
       	    },
       	 	{
       	        header 		: 'Stage',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 60,
       	        index		: 'stage'
       	    },
    	    {
    	       	header 		: 'Status',
      	        align		: 'left',
      	        sortable	: true,
      	        width		: 60,
       	        index		: 'status'
    	    },
       	    {
       	        header 		: 'Priority',
       	        align		: 'left',
       	        sortable	: true,
       	        width		: 60,
       	        index		: 'priority'
       	    },
       	    {hidden : true,index : 'companyName'},
       	    {hidden : true,index : 'companyAddress'},
       	    {
       	    	hidden		: true,
       	        index		: 'activityTypeId'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'salesPersonId'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'subject'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'duration'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'reminder'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'reminderDate'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'opportunityTitleId'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'stageId'
       	    },
       	    {
       	    	hidden		: true,
       	        index		: 'statusId'
       	    },
       	    {
    			xtype		: 'actioncolumn',
    			header  	: 'ACTION',
    			align		: 'center',
    			width		: 80,
       	        id          : 'activityActionColumn',
    			items		:[
	    			     	   {
	    						 icon	: '../images/view.jpg' ,
	    						 handler : function(cm, rowIndex, colIndex){
	    							 		var leadGrid = Ext.getCmp('spSearchLeadGridPanel');
	    							 		var customerGrid = Ext.getCmp('spSearchCustomerGridPanel');
	    							 		var activityGrid = Ext.getCmp('spSearchActivityGridPanel');
	    							 		var myActivityGrid = Ext.getCmp('myActivitiesGrid');
	    							 		if(leadGrid != null){
	    							 			var leadId = Ext.getCmp('leadId').getValue();
	    							 			var activityId = Ext.getCmp('activitiesGrid').store.getAt(rowIndex).get('id');
	    							 			showLeadActivityScreen(true, leadId, activityId);
	    							 		}
	    							 		if(customerGrid != null){
	    							 			var customerId = Ext.getCmp('customerId').getValue();
	    							 			var activityId = Ext.getCmp('activitiesGrid').store.getAt(rowIndex).get('id');
	    							 			showCustomerActivityScreen(true, customerId, activityId);
	    							 		}
	    							 		if(activityGrid != null){
	    										var record = Ext.getCmp('spSearchActivityGridPanel').store.getAt(rowIndex);
	    					         		    var selectedActivityId = record.get('id');
	    							 			showActivityDetails(selectedActivityId); //this method is in activity.js
	    							 		}
	    							 		/*
	    							 		if(myActivityGrid != null){
	    							 			var record = myActivityGrid.store.getAt(rowIndex);
	    							 			var selectedActivityId = record.get('id');
	    							 			showActivityDetails(selectedActivityId); //this method is in activity.js
	    							 		}*/
	    						 		}
	    	     	  			},
	    	     	  			'-',
	    	     	  			{
		    						 icon	: '../images/cross.gif',
		    						 id		: 'deleteIcon',
		    						 tooltip:'Delete',
		    						 handler: function() {
	       	    	                           showMessage();  //this method inside Activity.jsp to generate details
	            	    	                 }
	    	     	  			}
	    			     	  ]
    		}
       ]);
		return activityColumnModel;
	};
	
	
	
	CRM.SPComp.roleMasterDataArray=['roleid','roleName','roleDescription'];
	CRM.SPComp.createRoleMasterColumnModel = function(){
		var roleMasterColumnModel = new Ext.grid.ColumnModel([
       	    {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'roleid'
       	    },
       	    {
       	    	header     : 'Role Name',
       	    	width      : 150,
       	    	align      : 'left',
       	    	sortable   : true,
       	    	index      : 'roleName'
       	    },
       	    {
       	    	header     : 'Role Description',
       	    	width      : 190,
       	    	align      : 'left',
       	    	sortable   : true,
       	    	index      : 'roleDescription'
       	    	
       	    },
       	   {
    			xtype		: 'actioncolumn',
    			header  	: 'Remove',
    			align		: 'center',
    			width		: 80,
       	       items		:[{
	    						 icon	: '../images/cross.gif',
	    						 id		: 'deleteIcon',
	    						 tooltip:'Delete',
	    						 handler: function() {
       	    	                           showMessage();  //this method inside rolemaster.jsp to generate details
            	    	                 }
	    				 }]
    		}
       	 ]);
		return roleMasterColumnModel;
	};
	
	
    CRM.SPComp.userDataArray=['employeeId','firstName','middleInitial','lastName','title','empCode','email','phone1','phone2'];
	CRM.SPComp.createUserColumnModel = function(){
	var userColModel = new Ext.grid.ColumnModel([
	         {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'employeeId'
       	    }
       	    ,		                                 		
       	    {
       	        header 		: 'First Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'firstName'
       	    }
       	    ,
       	    {
       	        header 		: 'M.I.',
       	        align		: 'left',
       	        hidden		: true,
       	        index		: 'middleInitial',
       	        width		: 40
       	    },
       	 	{
       	        header 		: 'Last Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'lastName'
       	    }
       	    ,
       	   {
     	    	header      : 'Title',
     	    	align       : 'left',
     	    	index       : 'title',
     	    	sortable    : true
     	   },
     	   {
    	    	header      : 'EmpCode',
    	    	align       : 'left',
    	    	index       : 'empCode',
    	    	sortable    : true
    	   }
     	   ,
           {
    	       	header 		: 'Email',
    	       	width		: 170,
      	        align		: 'left',
      	        index       : 'email',
      	        sortable	: true
    	    },
       	 	{
       	        header 		: 'Phone(W)',
       	        width       : 120,
       	        align		: 'center',
       	        index       : 'phone1',
       	        hidden		: true
       	    },
       	 	{
       	        header 		: 'Phone(M)',
       	        width       : 120,
       	        align		: 'center',
       	        index       : 'phone2',
       	        sortable	: false
       	 	},
       	    {
    			xtype		: 'actioncolumn',
    			header  	: 'ACTION',
    			align		: 'center',
    			width		: 80,
     	        menuDisabled: true,
    			items		:[{
    						 icon	: '../images/view.jpg',
    						 handler : function(){
    							 			showUserInfoDetails(); //This method is in UserInfoDetails.js
   							 			}	 			
    			     	   },
	   	     	  			'-',
		     	  			{
	    						 icon	: '../images/cross.gif',
	    						 id		: 'deleteIcon',
	    						 tooltip:'Delete',
	    						 handler: function() {
	   	    	                           //	showMessage(); //this method inside ProjectModule.js to generate details
	        	    	                 }
	    				    }]
    		},
       ]);
    return userColModel;
	};
	
	
	CRM.SPComp.memberDataArray=['memberId','firstName','lastName','companyName','email','phone1',];
	CRM.SPComp.createMemberColumnModel = function(){
	var memberColModel = new Ext.grid.ColumnModel([
	                                             
	         {
       	    	header 		: 'Id',
       	        width		: 60,
       	        align		: 'center',
       	        sortable	: true,
       	        index		: 'memberId'
       	    }
       	    ,		                                 		
       	    {
       	        header 		: 'First Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'firstName'
       	    },
       	 	{
       	        header 		: 'Last Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'lastName'
       	    },
       	    {
       	        header 		: 'Company Name',
       	        align		: 'left',
       	        sortable	: true,
       	        index		: 'companyName'
       	    },
           {
    	       	header 		: 'Email',
    	       	width		: 170,
      	        align		: 'left',
      	        index       : 'email',
      	        sortable	: true
    	    },
       	 	{
       	        header 		: 'Phone(M)',
       	        width       : 120,
       	        align		: 'center',
       	        index       : 'phone1',
       	        sortable	: false
       	 	}
       ]);
    return memberColModel;
	};
	
	
	CRM.SPComp.projectDataArray=['id','projectName','contactPerson','status','priority'];
	CRM.SPComp.createProjectColumnModel = function(){
    var projectColModel = new Ext.grid.ColumnModel([
	 {
		 header     : 'id',
		 width      : 60,
		 align      :'center',
		 sortable   :true,
		 index      :'id'
	  },
	  {
		  header    :'Project Name',
		  width     :100,
		  align     :'center',
		  sortable  :true,
		  index     :'projectName'
	  },
	  {
		  header    : 'Contact Person',
		  width     : 120,
		  align     : 'center',
		  sortable  : true,
		  index     : 'contactPerson'
	  },
	  {
		  header    :'Status',
		  width     : 100,
		  align     :'center',
		  sortable  :true,
		  index     :'status'
	  },
	  {
		   header   :'Priority',
		   width    : 100,
		   align    :'center',
		   sortable :true,
		   index    :'priority'
	  },
	 {
			xtype		: 'actioncolumn',
			header  	: 'ACTION',
			align		: 'center',
			width		: 80,
 	        menuDisabled: true,
			items		:[
			     	   {
						 icon	: '../images/view.jpg',
						 handler : function(cm,rowIndex,col){
						     		  	var record = Ext.getCmp('spSearchProjectGridPanel').store.getAt(rowIndex);
						     		  	showDetails(record.get('id')); //this method is in project.js file
							 			disableProjectForm(); //this method is in project.js file 
							 			showIssue(record.get('id'));// this method is inProjectModule.js  
							 			showMember(record.get('id')); // this method is in ProjectModule.js file
							 			showTask(record.get('id')); // this method is in ProjectModule.js file
							 			showProjectDoc(record.get('id')); // this method is in ProjectModule.js file 
			     	                   }	 			
			     	   },
	     	  			'-',
	     	  			{
  						 icon	: '../images/viewform.png',
  						 handler: function(cm,rowIndex,col){
			     		     var searchProjects=Ext.getCmp('spSearchProjectGridPanel');
			     		     var griddata=searchProjects.store.getAt(rowIndex);
			     		     projectReportForm(griddata);  //this method is in ProjectReport.js file
					
			     	        }
  				       }
			     	  ]
		},
	                                               
   ]);
	return projectColModel;
};
	
	
	CRM.SPComp.commentDataArray = ['issueId','comment','updatedAt','status','updatedBy','assignedTo'];
	 CRM.SPComp.createCommentColumnModel = function(){ 
		 
	  var commentColModel = new Ext.grid.ColumnModel([ 
	  {
		  header    : 'Issue id', 
		  align     : 'center',
		  width     : 80,
		  sortable  : true,
		  index     : 'issueId'
	  },
	  {
		  header    : 'Comment',
		  align     : 'center',
		  width     :  180,
		  sortable  : true,
		  index     : 'comment'
	  },
	  {
		  header    : 'Update By',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'updatedBy'
	  },
	  {
		  header    : 'Updated Date',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'updatedat'
	  },
	  {
		  header    : 'Status',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'status'
	  },
	  {
		  header    : 'Assigned To',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'assignedTo'
	  } 
	  
    
   
  ]);


return commentColModel;
};

	// IssueDashBoard Image
	//Priority image path
	var High_Priority = '../images/high_priority2.gif';
	var Low_Priority  = '../images/Low_priority.jpeg';
	var Medium_Priority = '../images/High_Priority_1.jpeg';
	
	//Category image path
	var Bug= '../images/Bug.jpeg';
	var Enhancement = '../images/Enhancement.jpeg'; 
	var OtherCategory = '../images/OtherCategory.jpeg';
	
	// Status Image Path
	var Status_Inprocess = '../images/Inprogress_status.jpeg';
	var Status_Open = '../images/Open_status.jpeg';
	var Status_Close = '../images/Closed_Status.jpeg';
	var Status_Resolved ='../images/Resolved_status.jpeg';
	var Status_Testing = '../images/Testing_status.jpeg';
	
	 
	//Priority renderer function
	function renderPriorityIcon(val) {
	 if(val == 'High')
	return  '<img src="' + High_Priority  + '"> ' + val  ;
	 if(val == 'Low')
	     return  '<img src="' + Low_Priority   + '"> ' + val  ;
	 if(val == 'Medium')
	     return  '<img src="' + Medium_Priority  + '"> ' + val  ; 
	}

	//Category renderer function
	function renderCategoryIcon(val) {
	 if(val == 'Bug')
	 return  '<img src="' + Bug + '"> ' + val  ;
	 if(val == 'Enhancement')
	     return  '<img src="' +Enhancement  + '"> ' + val  ;
	 if(val == 'Other')
	     return  '<img src="' +OtherCategory  + '"> ' + val  ;
	 
	}


	//Status render function
	function renderIssuesStatusIcon(val) {
	 if(val == 'INPROCESS')  
	   return  '<img src="' + Status_Inprocess + '"> ' + val  ;
	  if(val == 'OPEN') 
		   return  '<img src="' + Status_Open + '"> ' + val  ;
	  if(val == 'TESTING') 
		    return  '<img src="' + Status_Testing + '"> ' + val  ;
	  if(val == 'RESOLVED') 
			   return  '<img src="' + Status_Resolved + '"> ' + val  ;
      if(val == 'CLOSED') 
		   return  '<img src="' + Status_Close + '"> ' + val  ;
}


CRM.SPComp.dashboardDataArray =['issueProjectId','issueId','issueCategory','issueCategoryId','issueProjectName','issueName','issueAssignedTo','issueAssignedToId',
                                'issuePriority','issuePriorityId','issueStatus','issueStatusId','issueResolution','issueResolutionId' ,'createdBy','date',
                                 'issueReason','issueModule','issueComplexity','issueComplexityId','targetDate','dateResolved'];
CRM.SPComp.createDashboardColumnModel = function(myIssueGrid){

var dashboardColModel =new Ext.grid.ColumnModel([  
     {hidden	: true,index : 'issueProjectId'},  
     {  
            header   : 'Issue Id',
            align    :'left',
            width    : 50, 
            sortable : true,
            index    : 'issueId'  
      },
      {
          header  :'Category',
          align   :'left',
          width   :100,
          sortable: true,
          index   :'issueCategory',
          renderer : renderCategoryIcon
          
     },
     {hidden	: true,index : 'issuecategoryId'}, 
     {
           header    : 'Project Name',
           align     : 'left',
           width     : 120,
           sortable  : true,
           index     :'issueProjectName' 
      },
      {
           header    :'Issue Name',
           align     :'left',
           width     : 120,
           sortable  : true,
           index     :'issueName'
       },
       {
            header  : 'Assigned To',
            align   :'left',
            width   : 100,
            sortable: true,
            index   :'issueAssignedTo'
            
        },
        {hidden	: true,index : 'issueAssignedToId'},  
        {
           header   :'Priority',
           align    :'left',
           width    : 100,
           sortable : true,
           index    : 'issuePriority',
           renderer  : renderPriorityIcon  
       }, 
       
       {hidden	: true,index : 'issuePriorityId'}, 
       {
           header  : 'Status',
           align   : 'left',
           width   : 100, 
           sortable: true,
           index   : 'issueStatus',
           renderer  :  renderIssuesStatusIcon
       },
       {hidden	: true,index : 'issueStatusId'},
       {
           header  :'Resolution',
           align   :'left',
           width   :100,
           sortable: true,
           index   :'IssueResolution'
        },
        {hidden	: true,index : 'issueResolutionId'}, 
        {
            header    : 'Created By',
            align     :'left',
            width     : 100,
            sortable  : true,
            index     :'createdBy'
         },
         {
          header  : 'Date',
          align   : 'left',
          width   : 100,
          sortable: true,
          index   : 'date'
        },
        {hidden : true,index : 'issueReason'}, 
        {hidden	: true,index : 'issueModule'},  
        {hidden	: true,index : 'issueComplexity'},
        {hidden	: true,index : 'issueComplexityId'},
        {hidden	: true,index : 'targetDate'},
        {hidden	: true,index : 'dateResolved'} ,
        
        {
        	xtype    :'actioncolumn', 
                header   : 'Action',
                align    : 'center', 
                width    : 100, 
                   items    :[
                              {
	     	                       icon     : '../images/Edit.jpeg', 
	     	                       tooltip  : 'Update',
	     	                       handler  : function(cm, rowIndex, colIndex){ 
	     	                                var issueDashBoardGrid = Ext.getCmp(myIssueGrid); 
	     	                                var rowData  = issueDashBoardGrid.store.getAt(rowIndex); 
	     	              				    issuePopupWindow( rowData,false,true);   // this method is in issueDetails.js   
	     	                } 
                             },'-', 
                            {
	                    	           icon      : '../images/view.jpg',
	                    	           tooltip   : 'View',
	                    	           handler   : function(cm, rowIndex, colIndex){
	 	                                     var issueDashBoardGrid = Ext.getCmp(myIssueGrid);
	 	              				         var rowData  = issueDashBoardGrid.store.getAt(rowIndex); 
	 	              				         issuePopupWindow( rowData,true,true);   // this method is in issueDetails.js
                             } 
                            },'-',
                            {
		 						       icon	  : '../images/Comment.jpeg',
		 						       handler : function(cm, rowIndex, colIndex){
											 		 var issueGridData = Ext.getCmp(myIssueGrid);
										 			 var rowData  = issueGridData.store.getAt(rowIndex);
										 			 showIssueUpdateWindow(rowData);// this function is in issueupdate.js
											     }
 						    }
                         
                       ]
               }
 ]);

 
 return dashboardColModel;
};
	
CRM.SPComp.SetupsDataArray=[];
	
	/*Project Issue Column Model */
	CRM.SPComp.projectTaskArray=['id','projectTaskName','projectTaskId','taskName','taskDetail','priorityTask','priorityTaskId',
	                              'mileStone','estmStarDate','estmEndDate','estmDuration','actualStartDT','actualEndDT',
	                              'assignTo','assignToId','createdBy','taskStatus','taskStatusId','taskResolution',
	                              'taskResolutionId','durationWithUnit','durationUnit','dueDays'];
	CRM.SPComp.projectTaskColModel=function(gridid){
		var projectTaskColm =new Ext.grid.ColumnModel([
		                                                
		{header   : 'Task Id',sortable : false,dataIndex    : 'id',width: 50}
		,
		{header   : 'Name',sortable : false,dataIndex    : 'taskName'}
		,
		{header   : 'Task Details',sortable : false,dataIndex    : 'taskDetail'}
		,
		{header   : 'Priority',width    : 80,sortable : false,dataIndex    : 'priorityTask'}
		,
		{header   : 'Priority',width    : 80,sortable : false,hidden    : true,dataIndex    : 'priorityTaskId'}
		,
		{header   : 'Duration',align    :'left',width    : 70,sortable : false,dataIndex    : 'estmDuration',hidden:true}
		,
		{header   : 'DurationUnit',align    :'left',width    : 80,sortable : false,dataIndex    : 'durationUnit',hidden:true}
		,
		{header   : 'Duration',align    :'left',width    : 80,sortable : false,dataIndex    : 'durationWithUnit'}
		,
		{header   : 'Start Date',align    :'left',width    : 80,sortable : false,dataIndex    : 'estmStarDate'}
		,
		{header   : 'Calculate<br/>Finish Date',align    :'left',width    : 120,sortable : false,dataIndex    : 'estmEndDate'}
		,
		{header   : 'Duration Due',align    :'left',width    : 100,sortable : false,dataIndex    : 'dueDays'}
		,
		{header   : 'Actual<br/> Finish Date',align    :'left',width    : 100,sortable : false,dataIndex    : 'actualEndDT'}
		,
		{header   : 'Status',align    :'left',width    : 80,sortable : false,dataIndex    : 'taskStatus'}
		,
		{header   : 'Status',dataIndex    : 'taskStatusId',hidden:true}
		,
		{header   : '%<br/> Complete',align    :'left',width    : 80,sortable : false,dataIndex:'percentCompleted'}
		,
		{header   : 'Created By',align    :'left',width    : 80,sortable : false,dataIndex    : 'createdBy'}
		,
		{header   : 'Assign To',align    :'left',width    : 80,sortable : false,dataIndex    : 'assignTo'}
		,
		{header   : 'Assign To',dataIndex    : 'assignToId',hidden:true}
		,
		{header   : 'Project Name',dataIndex    : 'projectTaskId',hidden:true}
		,
		{header   : 'Project Name',dataIndex    : 'projectTaskName',hidden:true}
		,
		{
   	     xtype    :'actioncolumn',
   	     header   : 'Action',
   	     align    : 'center', 
   	     width    : 130, 
   	     items		:[
   	          		  	{
   	          		  		icon  	: '../images/Update.jpeg',
   	          		  	    tooltip:'Update',
   	          		  		handler:function(cm,rowIndex,colIndex){
   	          		  		var taskHomegrid=Ext.getCmp(gridid);
   	          		  		var rowdata=taskHomegrid.store.getAt(rowIndex);
   	          		  			taskPupupWindow(rowdata,false,true);  //this method in projecttask.js
   	          		  		}
   	          		  	}, 
   	          		  	{
   	          		  		icon  	: '../images/view.jpg',
   	          		  		tooltip:'View',
   	          		  		handler:function(cm,rowIndex,colIndex){
   	          		  			var taskHomegrid=Ext.getCmp(gridid);
   	          		  			var rowdata=taskHomegrid.store.getAt(rowIndex);
   	          		  			taskPupupWindow(rowdata,true,true);//this method in projecttask.js
   	          		  		}
   	          		  	}/*,
   	          		  	{
	          		  		icon  	: '../images/cross.gif',
	          		  		tooltip:'Remove',
	          		  		handler:function(cm,rowIndex,colIndex){
   	          		  			var taskHomegrid=Ext.getCmp(gridid);
   	          		  			var rowdata=taskHomegrid.store.getAt(rowIndex);
   	          		  		taskPupupWindow(rowdata,true,true);//this method in projecttask.js
   	          		  		
   	          		  		}
   	          		  	}*/,
   	          		    {
						       icon	  : '../images/updateview.png',
						       handler : function(cm,rowIndex,colIndex){
   	          		  						var taskHomeGrid=Ext.getCmp( gridid);
   	          		  						var rowdata= taskHomeGrid.store.getAt(rowIndex);
   	          		  					   taskCommentPupupWindow(rowdata);  // this window is in TaskUpdate.js
   	          		  					
									}
						 }, 
   	          		  ]
		}
		
		
		
		]);
		return projectTaskColm;
	};
	
	CRM.SPComp.commentTaskDataArray = ['taskId','taskComment','taskUpdatedDate','taskUpdatedBy','taskAssignedTo','taskStatus'];
	 CRM.SPComp.createCommentColumnModel = function(){
		 
	  var commentTaskColModel = new Ext.grid.ColumnModel([ 
	  {
		  header    : 'Task id', 
		  align     : 'center',
		  width     : 80,
		  sortable  : true,
		  index     : 'taskId'
	  },
	  {
		  header    : 'Comment',
		  align     : 'center',
		  width     :  180,
		  sortable  : true,
		  index     : 'taskComment'
	  },
	  {
		  header    : 'Update By',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'taskUpdatedBy'
	  },
	  {
		  header    : 'Updated Date',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'taskUpdatedDate'
	  },
	  {
		  header    : 'Assigned To',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'taskAssignedTo'
	  },

	  {
		  header    : 'Status',
		  align     : 'center',
		  width     :  100,
		  sortable  : true,
		  index     : 'taskStatus'
	  },
	  
	  
	  
   
  
 ]);


return commentTaskColModel;
};

CRM.SPComp.salesCalenderArray=['dueDateString','name','assignTo','company','companyId','project','projectId'];
CRM.SPComp.calenderCalModel=function(){
	var calenderCM = new Ext.grid.ColumnModel([
	                                                    {header:'Due Date',sortable:true,dataIndex:'dueDateString'},
	                                                    {header:'Name',sortable:true,dataIndex:'name',width:250},
	                                                    {header:'AssignTo',sortable:true,dataIndex:'assignTo'},
	                                                    {header:'Company',sortable:true,dataIndex:'company',width:250},
	                                                    {header:'Project',sortable:true,dataIndex:'project',width:250}
	                                                    
	                         ]);
	return calenderCM;
	
};
	
})();